package plateforme.controlleur;
import java.sql.DriverManager;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;

public class ControlleurModifierPersonne extends HttpServlet {
	
/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, java.io.IOException {
		
		String connectionURL = "jdbc:mysql://localhost:3306/laas";
		Connection connection = null;
		try {
			 String  id=request.getParameter("id");
				String nom=request.getParameter("nom");
			   String prenom=request.getParameter("prenom");
			   String role=request.getParameter("role");
			   String specialite=request.getParameter("specialite");
			   String email=request.getParameter("email");
System.out.println(specialite);
			
      //System.out.println(id+nom+prenom);
		 
	   if(nom.length()!=0 && prenom.length()!=0  && role.length()!=0 && specialite.length()!=0 && email.length()!=0) { 
		 
		 Class.forName("com.mysql.jdbc.Driver");

			// Get a Connection to the database

			connection = (Connection) DriverManager.getConnection(
		  connectionURL, "root", "");
			
			String sql = "update  personne set nom='"+nom+"',prenom='"+prenom+"',role='"+role+"',email='"+email+"',fonction='"+specialite+"' where idperson="+id  ;

			Statement s = (Statement) connection.createStatement();

			s.executeUpdate(sql);
			response.sendRedirect("admin.jsp");
System.out.println("succes upadte");
		
			
	   
			// response.setContentType("text/html");
		 
		 
		  
	   }
	   else{
		  
		   //request.setAttribute("id", id);
		  
		   RequestDispatcher dispatcher = request.getRequestDispatcher("/erreurmodif.jsp");  
		   dispatcher.forward( request, response ); 
		     
		    
	   }

			

		   }catch(Exception e){

				  System.out.println("Exception is ;"+e);

				  }
		 
		    
		
		   
	}

}
